<?php
class BSHtml extends CHtml
{
	public static function activeLabel($model, $attribute, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' control-label';
		}
		else
		{
			$htmlOptions['class'] = 'control-label';
		}
		return parent::activeLabel($model, $attribute, $htmlOptions);
	}
	
	public static function activeLabelEx($model, $attribute, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' control-label';
		}
		else
		{
			$htmlOptions['class'] = 'control-label';
		}
		return parent::activeLabelEx($model, $attribute, $htmlOptions);
	}
	
	public static function activeTextField($model, $attribute, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' form-control';
		}
		else
		{
			$htmlOptions['class'] = 'form-control';
		}
		return parent::activeTextField($model, $attribute, $htmlOptions);
	}
	
	public static function activePasswordField($model, $attribute, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' form-control';
		}
		else
		{
			$htmlOptions['class'] = 'form-control';
		}
		return parent::activePasswordField($model, $attribute, $htmlOptions);
	}
	
	public static function submitButton($title, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' btn btn-primary';
		}
		else
		{
			$htmlOptions['class'] = 'btn btn-primary';
		}
		return parent::submitButton($title, $htmlOptions);
	}
	
	public static function beginForm($action='', $method='POST', $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' form-horizontal';
		}
		else
		{
			$htmlOptions['class'] = 'form-horizontal';
		}
		return parent::beginForm($action, $method, $htmlOptions);
	}
	
	public static function activeDropDownList($model, $attribute, $data, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' form-control';
		}
		else
		{
			$htmlOptions['class'] = 'form-control';
		}
		return parent::activeDropDownList($model, $attribute, $data, $htmlOptions);
	}
	
	public static function activeTextArea($model, $attribute, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' form-control';
		}
		else
		{
			$htmlOptions['class'] = 'form-control';
		}
		return parent::activeTextArea($model, $attribute, $htmlOptions);
	}
	
	public static function activeFileField($model, $attribute, $htmlOptions=array())
	{
		if(isset($htmlOptions['class']))
		{
			$htmlOptions['class'] .= ' form-control';
		}
		else
		{
			$htmlOptions['class'] = 'form-control';
		}
		return parent::activeFileField($model, $attribute, $htmlOptions);
	}
	
	public static function listData($models, $propertyIndex, $propertyValue, $label=false)
	{
		$data = parent::listData($models, $propertyIndex, $propertyValue);
		array_unshift($data, $label ? $label : '--- Выберите значение ---');
		return $data;
	}
}